package com.itheima.homework8.firstwork.two;



import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        //比较器排序
        TreeSet<Teacher> ts=new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int result=o1.getAge()-o2.getAge();
                result=result==0?(o1.getName().compareTo(o2.getName())):result;
                return result;
            }
        });
        ts.add(new Teacher("zhangsan",23));
        ts.add(new Teacher("lisi",24));
        ts.add(new Teacher("wangwu",25));
        ts.add(new Teacher("zhaoliu",23));
        ts.add(new Teacher("tianqi",23));
        System.out.println("ts = " + ts);
        //迭代器
        Iterator<Teacher> it = ts.iterator();
        while (it.hasNext()) {
            Teacher next = it.next();
            System.out.println("next = " + next);
        }

    }
}
